class Admin::MembersController < ApplicationController
  
  layout 'admin'
  require_role 'admin'

  def index
    @members = Member.paginate :page => params[:page], :order => 'members.created_at DESC'
  end
  
  def edit
    @member = Member.find_by_login(params[:id])
  end
  
  def update
    @member = Member.find_by_login(params[:id])
    if @member.update_attributes(params[:member])
      flash[:success] = 'Member data updated'
      redirect_to :action => 'index'
    else
      flash[:error] = 'Could not edit member data.'
      render :action => 'edit'
    end
  end
    
  def set_role
    @member = Member.find_by_login(params[:id])
    if request.post?
      @member.role = params[:member][:role]
      if @member.save
        flash[:notice] = 'Member role changed. At next login, member will have new permissions.'
      end
    end
  end
  
  def set_membership
    @member = Member.find_by_login(params[:id])
    if request.post?
      @member.membership = params[:member][:membership]
      if @member.save
        flash[:success] = 'Membership changed'
      end
    end
  end

end